<?php

class Bootstrap
{
	
function __construct(){		
	
	if(isset($_GET['url'])){
		$url = $_GET['url'];
		$url = rtrim($url,'/');
		$url = explode('/',$url);
		
		//controlador
		$controller = array_shift($url);
		//método
		if(!empty($url)){
			$method = array_shift($url);
		} 
		
		//argumentos
		if(!empty($url)){
			$args = $url;	
		}
		
		$path_controller = CONTROLLER.$controller.'.php';
		if(file_exists($path_controller)){
			$c = new $controller;
			$c->loadModel($controller);
			if(isset($method)){
				if(method_exists($c,$method)){
					if(isset($args)){
						$c->$method($args);
					} else {
						$c->$method();
					}
				} else {
					die('Method not exists');
				}
			} else {
				$c->main();	
			}
		} else {
			$c = new Error;
			$c->errorController();
			exit();
		}
	} else {
		//leva a página index
		$c = new Index;
		$c->main();
	}
}

}

?>